<?php

/*
 * tiers/index.phtml
 */
?>
<?php

$title = "Gestion des tiers";
$this->headTitle($title);
?>

<div class='content-head'>
    <h3>
	<?php echo $title; ?>	
    </h3>
    <div class="toolbar">
        <div title="Ajouter" class="toggle add">
            <a id='bt-add-tiers' href="<?php echo $this->url('RHX/default', array('controller'	 => 'tiers', 'action'	 => 'add')) ?>" style="display: block; width: 100%; height: 100%;" ></a>
        </div>
    </div>
</div>

<div class='content-body'>
    <div id='content-data'>
	<!-- AJAX LOADING -->
    </div>

</div>

<!-- Script -->
<script type='text/javascript'>
    
    
    var JsTiers = (function(){
        var isEmpty = function(selector){
                return $.trim($(selector).val()) === '';
            },
            isFloat = function(val){
                v = $.trim(val);
                patFloat = new RegExp(/^[0-9]*[.]{0,1}[0-9]+$/);

                return patFloat.test(v);                     
            }
            ;
            
        return {
            init : function(){
                var self = this;
                
                JsTiers.refresh();                
                JsTiers.initAdding();
            },
            refresh : function(){
                console.log('refresh');
                
                ajax = $.ajax({
                    type : "post",
                    url  : "<?php echo $this->url('RHX/default', array('controller'	 => 'tiers', 'action'	 => 'loadIndex')) ?>"
                    });
                ajax.success(function(data){
                    $('#content-data').html(data);
                });
                ajax.error(function(){
                    $("#content-data").html("<div class='rh-error'>Contenu Impossible à charger</div>");
                });
            },
            initAdding : function(){          
                /*$('#bt-add-tiers').click(function(e){
                    e.preventDefault();
                    alert ("L'ajout d'un Tiers est en cours de developpement");
                    window.location = "<?php echo $this->url('RHX/default', array('controller'	 => 'tiers', 'action'	 => 'loadIndex')) ?>";
                });*/
                
            }
        } 
    } )();
    
    $(document).bind('ready', JsTiers.init);
</script>
